package org.ruoyi.common.dhuman.utils;
import org.bytedeco.ffmpeg.global.avutil;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import java.io.File;

public class FFmpegAudioUtil {

	/**
	 * 获取音频时长（毫秒）
	 */
	public static long getAudioDuration(String audioPath) {
		FFmpegFrameGrabber grabber = null;
		try {
			grabber = new FFmpegFrameGrabber(audioPath);
			grabber.start();
			long duration = grabber.getLengthInTime() / 1000; // 微秒转毫秒
			grabber.stop();
			return duration;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		} finally {
			if (grabber != null) {
				try {
					grabber.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
	public static void main(String[] args) {
		String audioPath = "C:\\Users\\Admin\\Videos\\合并\\20251028.171029.586\\subPPT_0\\tts_1179119487945973760_1761290453.mp3";
		long duration = getAudioDuration(audioPath);
		System.out.println(duration);
	}
}
